package com.sinopec.basemodule.dialog;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sinopec.basemodule.R;
import com.sinopec.basemodule.widget.popupwindow.BasePopup;

/**
 * @author lwj
 * @ClassName: ExitPopupWindow
 * @Description: 退出登录弹窗
 */
public class ExitPopupWindow extends BasePopup<ExitPopupWindow> {
    private Context mContext;
    private OnSelectListener listener;
    //确认按钮
    private TextView tv_confirm;
    //取消按钮
    private TextView tv_cancel;

    public static ExitPopupWindow create(Context context, OnSelectListener listener) {
        return new ExitPopupWindow(context, listener);
    }

    public ExitPopupWindow(Context context, OnSelectListener listener) {
        this.listener = listener;
        this.mContext = context;
        setContext(context);
    }

    @Override
    protected void initAttributes() {
        setContentView(R.layout.exit_popupwindow);
        DisplayMetrics d = mContext.getResources().getDisplayMetrics();
        //设置弹窗宽高比例IntEKt.dp2px(370)
        this.setWidth((int) (d.widthPixels * 0.35));
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        setFocusAndOutsideEnable(true)
                .setBackgroundDimEnable(true)
                .setNeedReMeasureWH(true)
                .setDimValue(0.5f);

//        setContentView(R.layout.choose_warehouse_popupwindow, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        setFocusAndOutsideEnable(true)
//                .setBackgroundDimEnable(true)
//                .setNeedReMeasureWH(true)
//                .setDimValue(0.5f);
    }

    @Override
    protected void initViews(View view, ExitPopupWindow basePopup) {
        //确认按钮
        tv_confirm = view.findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(v -> {
            listener.onConfirm();
        });

        //取消按钮
        tv_cancel = view.findViewById(R.id.tv_cancel);
        tv_cancel.setOnClickListener(v -> {
            dismiss();
        });
    }

    public interface OnSelectListener {
        /**
         * 确认
         */
        void onConfirm();
    }
}
